package com.y.architecture.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.y.architecture.R;
import com.y.architecture.recycle_util.BaseQuickAdapter;
import com.y.architecture.recycle_util.BaseViewHolder;
import com.y.architecture.weather.Weather;

import java.util.List;


/**
 * Created by arvinljw on 17/5/15 00:10
 * Function：
 * Desc：
 */
public class WeatherListAdapter extends BaseQuickAdapter<Weather.HeWeather6Bean, BaseViewHolder> {

    public WeatherListAdapter(List<Weather.HeWeather6Bean> datas) {
        super(R.layout.item_weather, datas);
    }

    @Override
    protected void convert(BaseViewHolder helper, Weather.HeWeather6Bean item) {
        boolean isNoImg = true;
        if (item.getStatus().equals("ok")) {
            if (TextUtils.isEmpty(item.getNow().getTmp())) {
                isNoImg = false;
            }
//        } else {
//            if (item.getImages() == null || item.getImages().size() == 0) {
//                isNoImg = false;
//            }
        }
        if (isNoImg) {
            convertNoImage(helper, item);
            return;
        }
        convertItem(helper, item);
    }

    private void convertNoImage(BaseViewHolder helper, Weather.HeWeather6Bean item) {
        convertItem(helper, item);
        helper.getView(R.id.iv_item_CategoryAdapter).setVisibility(View.GONE);
    }

    private void convertItem(BaseViewHolder helper, Weather.HeWeather6Bean item) {
//        String url = "";
//        if (item.getType().equals("福利")) {
//            url = item.getUrl();
//        } else {
//            if (!TextUtils.isEmpty(item.getShowImage())) {
//                url = item.getShowImage();
//            }
//        }
        ImageView ivItem = helper.getView(R.id.iv_item_CategoryAdapter);
        ivItem.setVisibility(View.VISIBLE);
//        AFGlideUtil.loadImage(getRealSizeUrl(url), ivItem);


        helper.setText(R.id.tv_author_CategoryAdapter, "温度：" + item.getNow().getTmp());
        helper.setText(R.id.tv_source_CategoryAdapter, "天气：" + item.getNow().getCond_txt());
        helper.setText(R.id.tv_publish_time_CategoryAdapter, item.getUpdate().getUtc());
    }

//    private String getRealSizeUrl(String url) {
//        return url + "?imageView2/0/w/" + AFSizeUtil.dp2px(64);
//    }

}
